﻿using System;
using System.Collections.Generic;
using System.Web.Security;
using Be;
using WebGui.Admin;
using WebGui.BllBookingService;
using WebGui.BllLessonService;
using System.Linq;

namespace WebGui.User
{
    /// <summary>
    /// this it used to open a booking
    /// </summary>
    public partial class Open : System.Web.UI.Page
    {
        
        /// <summary>
        /// a object of a bebooking
        /// </summary>
        private BeBooking _event;
        /// <summary>
        /// a Lesson Service Client
        /// </summary>
        private LessonServiceClient _lesson;
        /// <summary>
        /// a Lesson Service Client
        /// </summary>
        private BookingServiceClient _booking;
        /// <summary>
        /// Loads the page.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event Arguments</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            _lesson = (LessonServiceClient) Session["Lesson"];
            _booking = (BookingServiceClient)Session["Booking"];
            if (!IsPostBack)
            {
            
            int id = Convert.ToInt32(Request.QueryString["id"]);
            LoadBooking(id);
            }
    }
        /// <summary>
        /// Loads the booking you are opening
        /// </summary>
        /// <param name="id">the id of the booking</param>
        private void LoadBooking(int id)
        {
            _event = _booking.GetBookingFromId(id);
            TxtStart.ReadOnly = true;
            TxtEnd.ReadOnly = true;
            TxtStartPlace.ReadOnly = true;
            TxtEndPlace.ReadOnly = true;
            TxtTecher.ReadOnly = true;
            TxtStart.Text = _event.StartTime + "";
            TxtEnd.Text = _event.EndTime + "";
            TxtStartPlace.Text = _event.StartLatitude + "," + _event.StartLongitude;
            TxtEndPlace.Text = _event.EndLatitude + "," + _event.EndLongitude;
            TxtTecher.Text = _event.TeacherId;
        }
        /// <summary>
        /// Closes the open page and modal
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event Arguments</param>
        protected void btnClose_Click(object sender, EventArgs e)
        {
            Modal.Close(this);
        }
    }
}